<?php
	session_start();
	
	if (!isset($_SESSION['sesi_login']))
		header("Location:../../index.php");
	
	@chdir("../../");
	define('ABS_URL',str_replace("\\","/",getcwd()));
	require ABS_URL.'/engine/Smarty.class.php';
	require ABS_URL."/functions/class.query.inc.php";
	$smarty = new Smarty();
	require ABS_URL."/dev_con.inc.php";
	require ABS_URL."/functions/func_file.php";
	$queryData = new queryData();
	$queryData->baseConfig();
	require ABS_URL."/functions/func_content.php";
	require ABS_URL."/langs/".BASE_LANGUAGE.'.inc.php';
	require $queryData->get_curr_dir(dirname(__FILE__))."/langs/".BASE_LANGUAGE.'.inc.php';

	$arr1 = array("http://".$_SERVER['HTTP_HOST']."/");
	$path = array('');
	
	$nama = trim(strip_tags($_POST['nama']));
	$url = strip_tags($_POST['deskripsi']);
	$author = strtolower($_SESSION['author']);
	$upbanner = trim($_POST['upbanner']);
	$tipe = $_POST['type'];
	$tanggal = date("Y-m-d-H-i-s");
	$thum = $_POST['nama_hid'];

	$upbanner = str_replace($arr1,$path,$upbanner);
	$info1 = pathinfo($upbanner);
	$info2 = file_info('../../'.$upbanner);
	$size = $info2['size'];
	$filename = basename($upbanner,'.'.$info1['extension']);
	$aext = file_ext($upbanner);
	$aext = strtolower($aext);
	$dirname = dirname($upbanner)."/";
	
	//echo $upanner." ".$size." ".$dirname." ".$filename." ".$aext;
	if (strtolower(ACT_VER)=="hapus") {
		$kode = (int) $_GET['kode'];
		
		$sqls = "SELECT * FROM tbl_upload WHERE idx='".$kode."' LIMIT 1";
		$qrys = mysql_query($sqls);
		$rows = mysql_fetch_object($qrys);
		$nm = explode("[spasi]",$rows->data);
		$dataku = "../../".$nm[0];
								
		if (file_exists($dataku)) {	
			unlink($dataku);
		};

		$sql = "DELETE FROM tbl_upload WHERE idx='".$kode."'";
		$qry = mysql_query($sql);

		($qry) ? $_SESSION['sesi_ver'] = $queryData->cekAksi($kode,'delete') : $_SESSION['sesi_ver'] = '';
		$act = 'lihat';
	} else {		
		$a = array($nama,$upbanner,$aext,$tipe);
		$b = array('empty','fileDataSize','fileData','empty');
		$c = array($DOWNLOAD_TITLE,$DOWNLOAD_FAILED_SIZE,$DOWNLOAD_FAILED_EXTENSION,$DOWNLOAD_TYPE);
		switch (strtolower($_POST['act_ver'])) {
			case "input" :
				$result = $queryData->NotificationCheck($a,$b,$c);
				if (empty($result)) {					
					$sql_upload = "INSERT INTO tbl_upload VALUES(NULL,'".$dirname.$filename.".".$aext."[spasi]".$nama."[spasi]".$ukuran."[spasi]".$url."[spasi]DW','".$tipe."','".$tanggal."','".$author."','".$tanggal_mulai."','".$tanggal_selesai."','".$hari."','".$jam_mulai."','".$jam_selesai."')";
					$qry_upload = mysql_query($sql_upload);
					$_SESSION['sesi_ver'] = $queryData->cekAksi($nama,'add');
					$act = 'lihat';
				} else {
					$_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
					foreach($result as $data) {
						$_SESSION['sesi_ver'] .= '<br />- '.$data;
					}
					$act = 'tambah';
				}
			break;
			case "edit" :
				$kode = (int) $_POST['kode'];
				$result = $queryData->NotificationCheck($a,$b,$c);
				if (!empty($upbanner)) {
					if (empty($result)) {						
						$sql_upload = "UPDATE tbl_upload SET data='".$dirname.$filename.".".$aext."[spasi]".$nama."[spasi]".$ukuran."[spasi]".$url."[spasi]DW', tipe='".$tipe."', tanggal='".$tanggal."' WHERE idx='".$kode."'";
						$qry_upload = mysql_query($sql_upload);
						$_SESSION['sesi_ver'] = $queryData->cekAksi($nama,'edit');
						$act = 'lihat';
					} else {
						$_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
						foreach($result as $data) {
							$_SESSION['sesi_ver'] .= '<br />- '.$data;
						}
						$act = 'tambah';
					}
				} else {
					$a = array($nama);
					$b = array('empty');
					$c = array($DOWNLOAD_TITLE);
					$result = $queryData->NotificationCheck($a,$b,$c);
					if (empty($result)) {						
						$sql_upload = "UPDATE tbl_upload SET data='".$thum."[spasi]".$nama."[spasi]".$ukuran."[spasi]".$url."[spasi]DW', tipe='".$tipe."', tanggal='".$tanggal."' WHERE idx='".$kode."'";
						$qry_upload = mysql_query($sql_upload);
						$_SESSION['sesi_ver'] = $queryData->cekAksi($nama,'edit');
						$act = 'lihat';
					} else {
						$_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
						foreach($result as $data) {
							$_SESSION['sesi_ver'] .= '<br />- '.$data;
						}
						$act = 'tambah';
					}
				}
			break;
		}
	}
	
	if (isset($_SESSION['sesi_login'])) {
		header('Location:../../?show='.SHOW.'&showview='.SHOWVIEW.'&act='.$act.'&limitdown=0');
	} else {
		header("Location:../../index.php");
	};
?>